package com.me.demoanimation;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;


public class simpleGui implements ApplicationListener {
	Skin skin ;
	Stage stage;
	SpriteBatch batch;
	
	
	@Override
	public void create() {		
		batch = new SpriteBatch();
		stage = new Stage();
		Gdx.input.setInputProcessor(stage);
		
		skin = new Skin();
		//
		Pixmap pixmap = new Pixmap(1,1,Format.RGBA8888);
		pixmap.setColor(Color.WHITE);
		pixmap.fill();
		skin.add("white", new Texture(pixmap));
		skin.add("default", new  BitmapFont());
		
		TextButtonStyle textButtonStyle = new TextButtonStyle();
		textButtonStyle.up = skin.newDrawable("white",Color.DARK_GRAY);
		textButtonStyle.down = skin.newDrawable("white",Color.DARK_GRAY);
		textButtonStyle.checked = skin.newDrawable("white",Color.BLUE);
		textButtonStyle.over = skin.newDrawable("white",Color.LIGHT_GRAY);
		textButtonStyle.font = skin.getFont("default");
		skin.add("default",textButtonStyle);
		//
		Table table = new Table();
		table.setFillParent(true);
		stage.addActor(table);
	    //
		final TextButton button = new TextButton("click  me",skin);
		table.add(button);
		
		button.addListener(new ChangeListener() {

			@Override
			public void changed(ChangeEvent event, Actor actor) {
				// TODO Auto-generated method stub
				System.out.println("clicked ! is checked : "+button.isChecked());
				button.setText("good job");
				
			}
			
				
			}
		);
		table.add(new Image(skin.newDrawable("white",Color.RED))).size(64);
		
	}

	@Override
	public void dispose() {
	  stage.dispose();
	  skin.dispose();
	}

	@Override
	public void render() {		
		Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1/30f));
		stage.draw();
		Table.drawDebug(stage);
		
	}

	@Override
	public void resize(int width, int height) {
		stage.setViewport(width, height, false);
	}

	@Override
	public void pause() {
	}

	@Override
	public void resume() {
	}
}

